{% extends 'myadmin/base.html' %}

{% block main_body %}


<div style="height:60px">

</div>


  <section class="content">

      <div class="container-fluid">
        <div class="row">
          <div class="col-12">

    <div class="card">
              <div class="card-header">
                <h3 class="card-title"><a href="{% url 'myadmin_image_index' %}">首页</a> >镜像管理</h3>
              </div>
              <div style="height:50px">
                <div style="width:120px;float:right;padding:10px;">
                   <button type="button" class="btn btn-block btn-primary" onclick="search()">浏览</button>
                </div>
               <div style="width:120px;float:right;padding:10px;">
                   <button type="button" class="btn btn-block btn-primary" onclick="add()">添加</button>
                </div>
                </div>

              <!-- /.card-header -->
              <div class="card-body">
                <table id="example2" class="table table-bordered table-hover">
                  <thead>
                  <tr>
                    <th>所有者</th>
                    <th>名称</th>
                    <th>状态</th>
                      <th>可见性</th>
                   <th>受保护的</th>
                      <th>磁盘格式</th>
                       <th>大小</th>
                        <th>创建日期</th>
                    <th>动作</th>
                  </tr>
                  </thead>
                  <tbody>
                  {% for image in imagelist %}
                  <tr>
                    <td>{{ image.owner }}</td>
                      <input type="hidden" id="imageid" value="{{ image.id }}" />
                    <td>{{ image.name }}</td>
                    <td>{{ image.status }}</td>
                    <td>{{ image.visibility }}</td>
                      <td>{% if image.protected == False %}
                         不
                        {% else %}
                        是
                        {% endif %}
                       </td>
                    <td>
                        {{ image.disk_format}}
                    </td>
                      <td>
                          <!--{%  widthratio 5 1 100 %} 上面的代码表示：5/1 *100，返回500，widthratio需要三个参数，它会使用 参数1/参数2*参数3，所以要进行乘法的话，就将参数2=1即可 -->
                          {% widthratio image.size|floatformat:2  1048576 1  %}MB
                       </td>
                       <td>
                        {{ image.created_at  }}
                       </td>
                    <td><a href="{% url 'myadmin_image_edit' image.id  %}?index=2" />编辑</a>  |  <a onclick="delimage()" style="cursor:pointer;" >删除</a> </td>
                  </tr>
                  {% endfor %}

                  </tfoot>
                </table>
              </div>
              <!-- /.card-body -->
            </div>
          </div>
        </div>
      </div>
  </section>


<script>
    function search() {
          window.location.href = "/myadmin/image/index";
    }
    function add() {
          window.location.href = "/myadmin/image/add?index=2";
    }
    function delimage(){
        if(confirm('确实要删除此镜像吗?')){
          id = document.getElementById('imageid').value;
          //alert(uid);
          window.location.href = "/myadmin/image/delete/"+id;
        }
    }
 </script>




{% endblock %}